package service

import (
	"encoding/json"
	"io"
	"net/http"
)

type Sentence struct {
	ID         int    `json:"id"`
	UUID       string `json:"uuid"`
	Hitokoto   string `json:"hitokoto"`
	Type       string `json:"type"`
	From       string `json:"from"`
	FromWho    string `json:"from_who"`
	Creator    string `json:"creator"`
	CreatorUID int    `json:"creator_uid"`
	Reviewer   int    `json:"reviewer"`
	CommitFrom string `json:"commit_from"`
	CreatedAt  string `json:"created_at"`
	Length     int    `json:"length"`
}

/* func DailySentence() (string, string, error) {

	r, err := http.Get("https://v1.hitokoto.cn/?c=a")
	if err != nil {
		return "", "", err
	}
	defer r.Body.Close()
	b, err := io.ReadAll(r.Body)

	if err != nil {
		return "", "", err
	}

	s := new(Sentence)
	if err := json.Unmarshal(b, s); err != nil {
		return "", "", err
	}

	return s.Hitokoto, s.From, nil
} */

func DailySentence() (*Sentence, error) {

	r, err := http.Get("https://v1.hitokoto.cn/?c=a")
	if err != nil {
		return nil, err
	}
	defer r.Body.Close()
	b, err := io.ReadAll(r.Body)

	if err != nil {
		return nil, err
	}

	s := new(Sentence)
	if err := json.Unmarshal(b, s); err != nil {
		return nil, err
	}

	return s, nil
}
